#define _WIN32_DCOM
#include <windows.h>
#include <iostream.h>
#include <stdio.h>

CLSID CLSID_TypeFactory = {0xB5866878, 0xBD99, 0x11D0, 0xB0, 0x4B, 0x00, 0xC0, 0x4F, 0xD9, 0x15, 0x50};
void main()
{
	HRESULT hr = 0;
	hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

	ITypeLib* pTypeLib = 0;
	GUID LIBID_Component = {0x10000003, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
    hr = LoadRegTypeLib(LIBID_Component, 1, 0, LANG_NEUTRAL, &pTypeLib);

	ITypeInfo* pTypeInfo = 0;
	IID IID_ISum = {0x10000001, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01};
    hr = pTypeLib->GetTypeInfoOfGuid(IID_ISum, &pTypeInfo);
	printf("hr = %0x\n", hr);

	ITypeFactory* pTypeFactory = 0;
	hr = CoGetClassObject(CLSID_TypeFactory, CLSCTX_INPROC_SERVER, 0, IID_ITypeFactory, (void**)&pTypeFactory);
	printf("hr = %0x\n", hr);

	IUnknown* pUnknown = 0;
	hr = pTypeFactory->CreateFromTypeInfo(pTypeInfo, IID_IUnknown, &pUnknown);
	printf("hr = %0x\n", hr);

	ITypeMarshal* pTypeMarshal = 0;
	hr = pUnknown->QueryInterface(IID_ITypeMarshal, (void**)&pTypeMarshal);
	printf("hr = %0x\n", hr);

	IMarshal* pMarshal = 0;
	hr = pTypeMarshal->QueryInterface(IID_IMarshal, (void**)&pMarshal);
	printf("hr = %0x\n", hr);

//	pTypeMarshal->
//  pMarshal->

	pMarshal->Release();
	pTypeMarshal->Release();
	pUnknown->Release();
	pTypeFactory->Release();

	CoUninitialize();
}